public class QuickSort<T extends java.lang.Comparable<? super T>> extends TestTimes implements SortInterface<T>
| Modifier and Type | Class and Description |
|---|---|
static class |
QuickSort.PivotType
This enum specifies the pivot type that QuickSort will use.
|
TestTimesInterface.MemoryUnits, TestTimesInterface.TimeUnits| Modifier and Type | Field and Description |
|---|---|
private QuickSort.PivotType |
pivotType |
| Constructor and Description |
|---|
QuickSort() |
| Modifier and Type | Method and Description |
|---|---|
void |
choosePivot(T[] array,
int first,
int last)
This method selects the
pivot according to the type of pivot specified. |
QuickSort.PivotType |
getPivotType()
A getter for the
PivotType being used. |
private int |
partition(T[] array,
int first,
int last)
This method first finds the pivot
p by calling choosePivot and
then partitions and rearranges the elements of the array in the following manner:
|
private void |
quickSort(T[] array,
int first,
int last)
This is the recursive method that implements the QuickSort algorithm.
|
void |
setPivotType(QuickSort.PivotType pivotType)
The setter for the
PivotType being used. |
void |
sort(T[] arrayToSort)
This is the method that users will call to sort the specified array of
Objects of type
T using QuickSort. |
addTestTime, getAverageMemoryUsage, getAverageTestTime, getLastMemoryUsage, getLastTestTime, getMemoryUnits, getMemoryUsages, getTestTimes, getTimeUnits, resetTestTimes, setMemoryUnits, setTimeUnitsprivate QuickSort.PivotType pivotType
public QuickSort.PivotType getPivotType()
PivotType being used. The default is FirstElement
See QuickSort.PivotTypePivotType being used.public void setPivotType(QuickSort.PivotType pivotType)
PivotType being used. See QuickSort.PivotTypepivotType - The PivotType to use.public void sort(T[] arrayToSort)
This is the method that users will call to sort the specified array of
Objects of type T using QuickSort. The method of choosing the pivot is
specified by properly setting the pivotType instance variable.
This method will call the quickSort method to perform the recursive sort.
The Comparable interface must either be implemented by T
or a superclass of T.
When this method is done, the specified array is sorted.
sort in interface SortInterface<T extends java.lang.Comparable<? super T>>arrayToSort - The array of Objects of type T to be sorted.private void quickSort(T[] array, int first, int last)
array - The array of Objects of type T to be sorted.first - Index of the first entry of the arraylast - Index of the last entry of the arraypublic void choosePivot(T[] array, int first, int last)
This method selects the pivot according to the type of pivot specified.
The chosen pivot will end up as the first element in the
specified array.
array - The array of Objects of type T to be sorted.first - Index of the first entry of the arraylast - Index of the last entry of the arrayprivate int partition(T[] array, int first, int last)
p by calling choosePivot and
then partitions and rearranges the elements of the array in the following manner:
{ [ elements < p ] p [ elements ≥ p] }.
array - The array of Objects of type T to be sorted.first - Index of the first entry of the arraylast - Index of the last entry of the arrayp after the partition.